var product = require('../Models/ProductModel');
var funs    = require('../fun/functions');
exports.productList = function(req,res){
	 var className = '';
	 var page = req.query.p?req.query.p:1;
	 if(req.query.class){
	 	className = req.query.class; 
	 }
	 var where = {className:className,'page':page,'num':16}
	 
	 
     product.getProductList(where,function(data){
     	product.getProductCountByClass(className,function(count){
     		var allcount = 0
     		if(typeof(count) != "undefined"){
     			allcount = count[0].count
     		}
     		var show = funs.getPage(req,allcount,16,{'class':className});
     		res.render('product',{list:data,'page':show})
     	})
        
     })
}
exports.productDetails = function(req,res){
	var product_id = req.query.product_id;
	
	product.getProductById(product_id,function(data){
           data[0]['c_content'] = funs.changePicUrl(data[0]['c_content'],'http://scbadmin.quyum.cn');
           res.render('product_details',{product:data[0]})
	})
}